package com.ivideo.avcore.rtmplive;

import android.media.AudioFormat;

/**
 * @author yaotianxue
 * @description 参数配置：视频、音频、rtmp
 * @date 2025/6/24
 */
public class Config {
    //视频参数
    /**
     * 视频的帧率
     */
    public final int fps;
    /**
     * 视频的最小宽度
     */
    public final int minWidth;
    /**
     * 视频的最大宽度
     */
    public final int maxWidth;

    /**
     * 视频编码的比特率：码率
     */
    public final int bitrate;

    public  final int iFrameInternal;

    //rtmp参数
    /**
     * RTMP连接超时时长
     */
    public final int timeOut;
    /**
     * 发布的url
     */
    public final String publishUrl;

    //音频参数
    /**
     * 音频的format
     */
    public final int audioFormat;
    /**
     * 音频你的channel
     */
    public final int channelConfig;
    public final int sampleRate;

    public Config(Builder builder) {
        this.timeOut = builder.timeOut;
        this.fps = builder.fps;
        this.minWidth =builder. minWidth;
        this.maxWidth =builder. maxWidth;
        this.publishUrl = builder.url;
        this.audioFormat = builder.audioFormat;
        this.channelConfig =builder. audioChannel;
        this.bitrate = builder.bitrate;
        this.sampleRate = builder.sampleRate;
        this.iFrameInternal = builder.iFrameInternal;
    }


    public static class Builder {
        private int fps = 30;
        private int minWidth = 320;
        private int maxWidth = 720;
        private int timeOut = 1000;
        private String url;
        private int iFrameInternal = 1;

        private int audioFormat = AudioFormat.ENCODING_PCM_16BIT; //采样位数
        private int audioChannel = AudioFormat.CHANNEL_CONFIGURATION_STEREO; //双通道

        private int bitrate = 700 * 1000; //码数
        private int sampleRate = 44100;

        /**
         * 设置采样率
         * @param sampleRate
         * @return
         */
        public Builder setSampleRate(int sampleRate){
            this.sampleRate = sampleRate;
            return this;
        }

        /**
         * 设置I帧间隔
         * @param iFrameInternal
         * @return
         */
        public Builder setIFrameInternal(int iFrameInternal) {
            this.iFrameInternal = iFrameInternal;
            return this;
        }
        /**
         * 设置帧率。
         *
         * @param fps 帧率
         * @return {@link Builder}
         */
        public Builder setFps(int fps) {
            this.fps = fps;
            return this;
        }

        /**
         * 设置最大宽度。
         *
         * @param maxWidth 最大宽度
         * @return {@link Builder}
         */
        public Builder setMaxWidth(int maxWidth) {
            this.maxWidth = maxWidth;
            return this;
        }


        /**
         * 设置最小宽度。
         *
         * @param minWidth 最小宽度
         * @return {@link Builder}
         */
        public Builder setMinWidth(int minWidth) {
            this.minWidth = minWidth;
            return this;
        }

        /**
         * 设置发布的url。
         *
         * @param url 发布的url
         * @return {@link Builder}
         */
        public Builder setUrl(String url) {
            this.url = url;
            return this;
        }

        /**
         * 设置AudioChannel。
         *
         * @param audioChannel audioChannel
         */
        public Builder setAudioChannel(int audioChannel) {
            this.audioChannel = audioChannel;
            return this;
        }

        /**
         * 设置audioFormat。
         *
         * @param audioFormat audioFormat
         */
        public Builder setAudioFormat(int audioFormat) {
            this.audioFormat = audioFormat;
            return this;
        }

        /**
         * 设置编码比特率。
         *
         * @param bitrate 视频编码比特
         */
        public Builder setBitrate(int bitrate) {
            this.bitrate = bitrate;
            return this;
        }

        /**
         * 建造Config
         *
         * @return {@link Config}
         */
        public Config build() {
            Config config = new Config(this);
            return config;
        }
    }



}
